<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>一键微博</title>

<style type="text/css">
body{
	width:530px;
}

#userinfo {
	width: 220px;
	-webkit-border-radius:5px 5px 5px 5px;
	background:none repeat scroll 0 0 #ffde00;
	padding:5px;
}

#nouser{
	width: 220px;
	-webkit-border-radius:5px 5px 5px 5px;
	background:none repeat scroll 0 0 #ffde00;
	padding:5px;
}

a{
	text-decoration:none;
	border:none;
	outline:none;
}

img{
	border:none;
}


#vipBtn{
	margin-left:10px;
}

#login{
	float:right;
	margin-top:-23px;
}

#pop_1{
	float:left;
}

#lf {
	margin-left:60px;
	line-height:5px;
}

#user_head{
	min-height:60px;
}

.userdata{
	list-style:none;
	float:left;
	margin-left:10px;
	text-align:center;
}

ul{
	margin:0;
	padding:0;
}

.num{
	font-weight:bold;
}

#user_atten{
	color:blue;
	height:60px;
	border-bottom:1px dotted #FFFFFF;
}

#user_atten a{
	color:blue;
}

em{
	font-size:12px;
}

#desc{
	font-size:14px;
	line-height:1.3em;
}

#links{
	margin-left:20px;
}

.overlay {
	-webkit-border-radius:12px 12px 12px 12px;
	background:none repeat scroll 0 0 #FFFFFF;
	width:220px;
}

.area_on{
	display:block;
}

.area_off{
	display:none;
}

#vipBtn{
	height:26px;
}

.badge{
	color:red;
	font-weight:bold;
}

table{
	text-align:left;
}
	
</style>
<script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script type="text/javascript" src="auth.js"></script>
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js"></script>
  <script src="Calendar.js"></script>
  
<script type="text/javascript">
var cal = new Calendar();
cal.drawCurrent();

////////////Face//////////////////////
var emotions;
var timeLine;
function getTimeLine()
{
    	 var url = "http://api.t.sina.com.cn/statuses/user_timeline.json";
	 var userid=oauth.getUserId();
	  var request = {
	    'method': 'get',
	    'parameters':{
	    	'user_id':userid,
	    	'count':1
	    	
	    }
	  };

	  oauth.sendSignedRequest(url, displayTimeLine, request);

}

function displayTimeLine(response)
{
    return response;
}

function getEmo()
{
            	 var url = "http://api.t.sina.com.cn/emotions.json";
	 var userid=oauth.getUserId();
	  var request = {
	    'method': 'get',
	    'parameters':{
	    	'type':'face' //"face":普通表情，"ani"：魔法表情，"cartoon"：动漫表情
	    }
	  };

	  oauth.sendSignedRequest(url, displayEmo, request);

}

function displayEmo(response)
{
    return response;
}

function getEmoImgUrl(emoText)
{
    var url;
    if(!emotions || !emoText)return;
    $.each(emotions, function(i, val)
    {
        if(val.text == emoText)
        {
            url = val.url;
            return false;
        }
    });
    
    return url;
}


//  $(document).ready(function() {
//    $("#datepicker").datepicker();
//    
//    var date = $("#datepicker").datepicker( "getDate" );
//    var mon = date.getMonth();
//    var days = $("#datepicker").find("table>tbody>tr>td>a");

//        timeLine = getTimeLine();
//emotions = getEmo();

//    alert(timeLine);
//    alert(emotions);

//        if(timeLine)
//        {
//            var found = false;
//            $.each(timeLine, function(i, val){
//                var c = new Date(val.created_at);
//                if(mon == c.getMonth())
//                {
//                    var data = val.text;
//                   var reg = /\[[\u4e00-\u9fa5]\]/gi;
//                   var arrMactches = data.match(reg);
//                   
//                   $.each(arrMactches, function(i, val)
//                   {
//                       var url = getEmoImgUrl(val);
//                       if(url)
//                       {
//                       alert(url);
//                            $.each(days, function(i, val)
//                            {
//                                if($(this).text=c.getDay())
//                                {
//                                    found = true;
//                                    $(this).css("background-image","url(" + url + ")");
//                                    return false;
//                                }
//                            });
//                            
//                            if(found)return false;
//                       }
//                   });
//                    
//                    if(found)return false;
//                }
//            });
//        }
//    
//  });

	function caldays(str){
		var arr=str.split(' ');
		var ct=Date.parse(arr[1]+" "+arr[2]+", "+arr[5]);
		var nt=Date.parse(new Date());
		return Math.ceil((nt-ct)/(1000*60*60*24));
	}
	
	function linkgo(url){
		chrome.tabs.create({
				"url":url
			});
		}


	function fill(info){
		var ROOT_URL="http://t.sina.com.cn/"+info.id+"/";

		if(!info.verified){
				hide("vippic");
			}
		
		var headpic=document.getElementById('headpic');
		headpic.src=info.profile_image_url;
		var username=document.getElementById('user_name');
		username.innerHTML=info.screen_name;
		username.href="http://t.sina.com.cn/"+info.domain;
		var location=document.getElementById('location');
		if(info.location){
			location.innerHTML="@"+info.location;
		}
		var desc=document.getElementById('desc');
		if(info.description){
			desc.innerHTML=info.description;
		}
		var num=document.getElementById('attentions');
		num.href=ROOT_URL+"follow";
		num.innerHTML=info.friends_count;
		var num=document.getElementById('myfans');
		num.href=ROOT_URL+"fans";
		num.innerHTML=info.followers_count;
		var num=document.getElementById('mblog');
		num.href=ROOT_URL+"profile";
		num.innerHTML=info.statuses_count;
		var num=document.getElementById("myfav");
		num.innerHTML=info.favourites_count;
		var num=document.getElementById('mydays');
		num.innerHTML=caldays(info.created_at);
	}

	function load(){
		if(oauth.hasToken()){
			getuserinfo();
			 chrome.browserAction.setBadgeText({
				  'text':''
			  });
			var new_status=localStorage.getItem("wb_new_status");
			var bd=document.getElementById("bd_st");
			if(new_status&&new_status>0){
					bd.innerHTML=new_status;	
				}else{
					bd.innerHTML="";	
					}
			var mentions=localStorage.getItem("wb_mentions");
			var bd=document.getElementById("bd_at");
			if(mentions&&mentions>0){
					bd.innerHTML=mentions;	
				}else{
					bd.innerHTML="";	
					}
			var dm=localStorage.getItem("wb_dm");
			var bd=document.getElementById("bd_dm");
			if(dm&&dm>0){
				bd.innerHTML=dm;	
				}else{
					bd.innerHTML="";	
					}
			var followers=localStorage.getItem("wb_followers");
			var bd=document.getElementById("bd_fw");
			if(followers&&followers>0){
				bd.innerHTML=followers;	
				}else{
					bd.innerHTML="";	
					}
			var comments=localStorage.getItem("wb_comments");
			var bd=document.getElementById("bd_cm");
			if(comments&&comments>0){
				bd.innerHTML=comments;	
				}else{
					bd.innerHTML="";	
					}
			}else{
				hide('userinfo');
				}
		}
	
</script>
</head>
<body onload="load();">
<input id="Button1" type="button" value="Time Line" onclick="getTimeLine();" />
    <input id="Button2" type="button" value="Emo" onclick="getEmo();" />
    <div type="text" id="datepicker"></div>

    <script type="text/javascript">
    var monthDay = [31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31];
    var currentDate = new Date();
    function displayMonth(date)
    {
        var firstDay = date;
        firstDay.setDay(1);
    }
    
    </script>
    
    <div>
        		<table id="calendar" cellspacing="0">
			<thead>
				<tr>
					<th>Mon</th><th>Tue</th><th>Wed</th>
					<th>Thu</th><th>Fri</th><th>Sat</th>
					<th>Sun</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td class="padding" colspan="3"></td>
					<td> 1</td>
					<td> 2</td>
					<td> 3</td>
					<td> 4</td>
				</tr>
				<tr>
					<td> 5</td>
					<td> 6</td>
					<td> 7</td>
					<td> 8</td>
					<td class="today"> 9</td>
					<td>10</td>
					<td>11</td>
				</tr>
				<tr>
					<td>12</td>
					<td class="date_has_event">
						13
						<div class="events">
							<ul>
								<li>
									<span class="title">Event 1</span>
									<span class="desc">Lorem ipsum dolor sit amet, consectetu adipisicing elit.</span>
								</li>
								<li>
									<span class="title">Event 2</span>
									<span class="desc">Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span>
								</li>
							</ul>
						</div>
					</td>
					<td>14</td>
					<td>15</td>
					<td>16</td>
					<td>17</td>
					<td>18</td>
				</tr>
				<tr>
					<td>19</td>
					<td>20</td>
					<td>21</td>
					<td class="date_has_event">
						22
						<div class="events">
							<ul>
								<li>
									<span class="title">Event 1</span>
									<span class="desc">Lorem ipsum dolor sit amet, consectetu adipisicing elit.</span>
								</li>
								<li>
									<span class="title">Event 2</span>
									<span class="desc">Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span>
								</li>
							</ul>
						</div>
					</td>
					<td>23</td>
					<td>24</td>
					<td>25</td>
				</tr>	
				<tr>
					<td>26</td>
					<td>27</td>
					<td>28</td>
					<td>29</td>
					<td>30</td>
					<td>31</td>
					<td class="padding"></td>
				</tr>
			</tbody>
			<tfoot>
				<th>Mon</th><th>Tue</th><th>Wed</th>
				<th>Thu</th><th>Fri</th><th>Sat</th>
				<th>Sun</th>
			</tfoot>
		</table>
    
    </div>
    
    
<div id="nouser">
	用户未授权，<a href="javascript:void(0);" onclick="login();">点击此处授权</a>。
</div>

<div style="display:none"
<div id="userinfo">
<div id="btnlog">
	<div id="vipBtn">
		<img id="vippic" alt="新浪认证用户" src="http://timg.sjs.sinajs.cn/t3/style/images/index/sina.png">
	</div>
	<div id="login">
		已授权，<a  href="javascript:void(0);" onclick="logout();">退出</a>
	</div>
</div>	
<div id="user_head">
<div id="pop_1" class="picborder_r lf"><a
	href="http://t.sina.com.cn/person/myface.php" onclick="linkgo(this.href);return false;"><img
	width=50 height=50
	title="" id="headpic"
	src=""></a>
</div>
<div id="lf">
<p class="font_14">
<a id="user_name" href="" onclick="linkgo(this.href);return false;"></a>
<span class="badge" id="bd_st"></span>
</p>
<p></p>
<p><em id="location"></em></p>
<p id="desc"></p>
</div>
</div>
<div id="user_atten">
<ul id="profile_following_follower_update">
	<li class="userdata">
	<div class="num"><a id="attentions"
		href="" onclick="linkgo(this.href);return false;"></a></div>
	关注</li>
	<li class="userdata">
	<div class="num"><a id="myfans" href="" onclick="linkgo(this.href);return false;"></a></div>
	粉丝<span class="badge" id="bd_fw"></span></li>
	<li class="userdata">
	<div class="num"><a id="mblog" href="" onclick="linkgo(this.href);return false;"></a></div>
	微博</li>
	<li class="userdata">
	<div class="num"><a id="myfav" href="http://t.sina.com.cn/favs" onclick="linkgo(this.href);return false;"></a></div>
	收藏</li>
	<li class="userdata">
	<div class="num"><a id="mydays"></a></div>
	天</li>
</ul>
</div>
<div id="links">
	<table cellpadding="5px">
		<tr>
			<td width=100>
				<a href="http://t.sina.com.cn/atme" onclick="linkgo(this.href);return false;">@我的</a>
				<span class="badge" id="bd_at"></span>
			</td>
			<td width=100>
				<a href="http://t.sina.com.cn/comments" onclick="linkgo(this.href);return false;">我的评论</a>
				<span class="badge" id="bd_cm"></span>
			</td>
		</tr>
		<tr>
			<td>
				<a href="http://t.sina.com.cn/messages" onclick="linkgo(this.href);return false;">我的私信</a>
				<span class="badge" id="bd_dm"></span>
			</td>
			<td>
				<a href="http://t.sina.com.cn/pub" onclick="linkgo(this.href);return false;">微博广场</a>
			</td>
		</tr>
		<tr>
			<td>
				<a href="http://t.sina.com.cn/dzone" onclick="linkgo(this.href);return false;">作者微博</a>
			</td>
			<td>
				<a href="http://t.sina.com.cn/app" onclick="linkgo(this.href);return false;">微博应用</a>
			</td>
		</tr>
	</table>
	
</div>
<br>
<center><a href="javascript:void(0);" onclick="recommend();">点此向好友推荐“一键微博”</a></center>
</div>
</div>
</body>
</html>